const {filesFinder,findPathFiles,writeTsConfig}=require("./util");
const inquirer = require('inquirer');
const paths=require("../config/paths");
const path=require("path");
const build=require("./build");
const docgen=require("./docgen");

const cli=async ()=>{
  const components=await filesFinder();
  const answers=await  inquirer.prompt([{
    type: 'list',
    name: 'component',
    choices:components,
    message: '请选择要打包的组件',
  },{
    type: 'input',
    name: 'version',
    message: '请输入版本号',
  }]);
  const componentPath=path.join(paths.components,answers.component);
  const componentFiles=await findPathFiles(componentPath);
  console.log("改写tsconfig文件!");
  await writeTsConfig(answers.component);
  console.log("改写tsconfig文件成功!");
  console.log("开始打包!");
  await build(answers,componentFiles);
  console.log("生成文档中");
  await docgen(answers.component);
  console.log("打包成功!");
}


cli();